<?php
error_reporting(E_ALL ^E_NOTICE );
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    //初始化View环境
    protected function _initView()
    {
        $options = $this->getOptions();
       	//print_r($options);
      
        $viewOptions = $options['resources']['view'];
        $view = new Zend_View($viewOptions);
        if (!empty($viewOptions['params'])) {
            foreach ($viewOptions['params'] as $key => $value) {
                $view->$key = $value;
            }
        }
        
        $view->env = $this->getEnvironment();
        $view->bootstrap = $this;
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setView($view);
      	//视图助手路径
		$view->addHelperPath($viewOptions['helperPath'],$viewOptions['helperPathPrefix']);
       // return $view;
    }
  
 
    protected function _initRouter()
    {
    	
        // Get Front Controller Instance
		$front = Zend_Controller_Front::getInstance();
		// Get Router
		$router = $front->getRouter();
		$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
          ':username.jia.com',
          array(
            'module'     => 'default',
	        'controller' => 'index',
	        'action'     => 'index'
          )
      	);
      	
      	$router->addRoute('companyroute', $hostnameRoute);
		
		//文章
		$memberarticle = new Zend_Controller_Router_Route_Regex(
	    	'news',
		    array(
		    	'module'     => 'default',
		        'controller' => 'news',
		        'action'     => 'index'
		    ),
		    array(
		        1 => 'uid'
		    ),
		    'news'
		);
		$router->addRoute('memberarticle', $memberarticle);
		
		
		
		$memberset = new Zend_Controller_Router_Route_Regex(
	    	'memberset',
		    array(
		    	'module'     => 'default',
		        'controller' => 'modules',
		        'action'     => 'edit'
		    ),
		    array(
		        1 => 'uid'
		    ),
		    'memberset'
		);
		$router->addRoute('memberset', $memberset);
		
		$membersave = new Zend_Controller_Router_Route_Regex(
	    	'membersave',
		    array(
		    	'module'     => 'default',
		        'controller' => 'modules',
		        'action'     => 'save'
		    ),
		    array(
		      1=> 'uid'
		    ),
		    'membersave'
		);
		$router->addRoute('membersave', $membersave);
		
		
		$productnav = new Zend_Controller_Router_Route_Regex(
	    	'product',
		    array(
		    	'module'     => 'default',
		        'controller' => 'product',
		        'action'     => 'index'
		    ),
		    array(
		      1=> 'uid'
		    ),
		    'product'
		);
		$router->addRoute('productnav', $productnav);
		
		//留言
		$guestbooknav = new Zend_Controller_Router_Route_Regex(
	    	'guestbook',
		    array(
		    	'module'     => 'default',
		        'controller' => 'guestbook',
		        'action'     => 'index'
		    ),
		    array(
		      1=> 'uid'
		    ),
		    'guestbook'
		);
		$router->addRoute('guestbooknav', $guestbooknav);
		
		
		$articlenav = new Zend_Controller_Router_Route_Regex(
	    	'news',
		    array(
		    	'module'     => 'default',
		        'controller' => 'news',
		        'action'     => 'index'
		    ),
		    array(
		      1=> 'uid'
		    ),
		    'news'
		);
		$router->addRoute('newsnav', $articlenav);
		
		//企业简介
		$aboutnav = new Zend_Controller_Router_Route_Regex(
	    	'about',
		    array(
		    	'module'     => 'default',
		        'controller' => 'about',
		        'action'     => 'index'
		    ),
		    array(
		        1 => 'uid'
		    ),
		    'about'
		);
		$router->addRoute('aboutnav', $aboutnav);
		
		
		
		$linknav = new Zend_Controller_Router_Route_Regex(
	    	'link',
		    array(
		    	'module'     => 'default',
		        'controller' => 'link',
		        'action'     => 'index'
		    ),
		    array(
		        1 => 'uid'
		    ),
		    'link'
		);
		$router->addRoute('linknav', $linknav);
		
		
		$contactnav = new Zend_Controller_Router_Route_Regex(
	    	'contact',
		    array(
		    	'module'     => 'default',
		        'controller' => 'contact',
		        'action'     => 'index'
		    ),
		    array(
		        1 => 'uid'
		    ),
		    'contact'
		);
		$router->addRoute('contactnav', $contactnav);

		
		
	

		
        
   } 
   

    
    protected function _initDB()
    {
    	$options = $this->getOption('resources');
        $options = $options['db'];

    	$resources = $this->getPluginResource('db');
        $db = $resources->getDbAdapter();
		Zend_Db_Table::setDefaultAdapter($db);
		//Zend_Registry::set('db',$db);
		define('AUTHSTRING',$options['params']['authstring']);
    	Zend_Registry::set('dbprefix',$options['params']['prefix']);

    }

    
        // To init the translate
    protected function _initTranslate()
    {
    	
    	
        $options = $this->getOption('resources');
        $options = $options['translate'];
        if (!isset($options['data'])) {
            throw new Zend_Application_Resource_Exception('No translation source data provided.');
        }
        $adapter = isset($options['adapter']) ? $options['adapter'] : Zend_Translate::AN_ARRAY;
        $session = new Zend_Session_Namespace('locale');
        if ($session->locale) {
            $locale = $session->locale;
        } else {
            $locale  = isset($options['locale'])  
                         ? $options['locale']
                         : null;
        }

        $data = '';
        if (isset($options['data'][$locale])) {
            $data = $options['data'][$locale];
        }
        $translateOptions = isset($options['options']) 
                                     ? $options['options']
                                     : array();

     
		
		Zend_Form::setDefaultTranslator($translate);
        
		Zend_Registry::set('Zend_Translate', $translate);
		
		
        return $translate;
       
    }
    
	
}





